package com.ljh.mboxvidoserver.console.shop.controller;

import com.ljh.mboxvidoserver.common.result.entity.Result;
import com.ljh.mboxvidoserver.console.shop.entity.Shop;
import com.ljh.mboxvidoserver.console.shop.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = "shop")
public class ShopController {

    @Autowired
    private ShopService shopService;
    /**
     * 静态视图跳转
     * @param path
     * @param model
     * @return
     */
    @RequestMapping(value = "/view/{path}")
    public ModelAndView view(@PathVariable(value = "path") String path, ModelAndView model){
        model.setViewName("console/shop/"+path);
        return model;
    }

    /**
     * 分页查询
     * @param shop
     * @param pageable
     * @param model
     * @return
     */
    @GetMapping("findShopPage")
    public ModelAndView findShopPage(Shop shop, Pageable pageable, ModelAndView model){
        try {
            Page<Shop> page = shopService.findList(shop, pageable);
            model.addObject("pager", page);
            model.setViewName("console/shop/shop_list");
        }catch (Exception e){
            e.printStackTrace();
        }
        return model;
    }

    /**
     * 查询单个实体数据
     * @param shop
     * @param model
     * @return
     */
    @GetMapping("findShopOne")
    public ModelAndView findShopOne(Shop shop, ModelAndView model){
        return model;
    }

    /**
     * 保存商品实体类
     * @param shop
     * @param session
     * @return
     */
    @PostMapping(value = "saveShop")
    @ResponseBody
    public Result saveShopType(Shop shop, HttpSession session){
        return null;
    }

    /**
     * 删除商品实体类
     * @param shop
     * @param session
     * @return
     */
    @PostMapping(value = "deleteShopType")
    @ResponseBody
    public Result deleteShopType(Shop shop, HttpSession session){
        return null;
    }

    /**
     * 修改商品实体类
     * @param shop
     * @param session
     * @return
     */
    @PostMapping(value = "updateShop")
    @ResponseBody
    public Result updateShop(Shop shop, HttpSession session){
        return null;
    }
}
